
    $("#modal_set_pwd").modal({
        show:false,
        backdrop: "static",//点击空白处不关闭对话框
    });
    $("#modal_set_phone").modal({
        show:false,
        backdrop: "static",//点击空白处不关闭对话框
    });

function check_pwd1() {
    var pwd = document.getElementById("password1");
    var pwdReg = /^[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]*((\d+[a-zA-Z]+)|(\d+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+)|([a-zA-Z]+\d+)|([a-zA-Z]+[-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+)|([-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+\d+)|([-`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]+[a-zA-Z]+))[-\da-zA-Z`=\\\[\];',./~!@#$%^&*()_+|{}:"<>?]*$/;
    var msg = document.getElementById("testpwd1");
    if (pwdReg.test(pwd.value)){
        msg.style.color="green";
        msg.innerHTML = "√";
        return true;
    } else {
        msg.style.color="red";
        msg.innerHTML="请输入8-20位中英文/数字密码！";
        return false;
    }
}
function check_pwd2() {
    var pwd1 = $("#password1").val();
    var pwd2 = $("#password2").val();
    var msg2 = document.getElementById("testpwd2");
    if (pwd1 == pwd2 && pwd2 != ""){
        msg2.style.color="green";
        msg2.innerHTML = "√";
        return true;
    } else {
        msg2.style.color="red";
        msg2.innerHTML="密码不一致！";
        return false;
    }
}

$("#psw_set").click(function () {
    var pwd1 = $("#password1").val();
    var pwd2 = $("#password2").val();
    if (pwd1 != pwd2 || pwd2 == "") {
        return false;
    }else {
        let userPassword = $("#password1").val();
        $.ajax({
                url: url + "/userInfo/updateUserInfo",
                type: "post",
                data: "userPassword=" + userPassword,
                dataType: "json",
                success: function (data) {
                    layer.msg("修改密码成功！请您重新登录！")
                    console.log(data)
                    $.ajax({
                        url: url + "/userInfo/exit",
                        type: "post",
                        data: "userPassword=" + userPassword,
                        dataType: "json",
                        success:function (data) {
                            setTimeout(function (){
                                location.href ="http://localhost:63342/sdkd-parent/web/webapp/user/html/login.html"
                            }, 1000);
                        }
                    })
                }
            })
       }
})

//点击获取验证码
$("#code_request").click(function () {
    var phone = $("#cur-phone").text()
    $.ajax({
        url:url +"/userInfo/getRandomPhoneCode",
        dataType:"json",
        type:"post",
        data:"phone="+phone,
        success:function (data) {
            console.log(data)
        }
    })
})

//点击获取新手机的验证码
$("#code_request2").click(function () {
    var phone =$("#phone2").val()
    $.ajax({
        url:url +"/userInfo/getRandomPhoneCode",
        dataType:"json",
        type:"post",
        data:"phone=" + phone,
        success:function (data) {
            console.log(data)
        }
    })
})

//输入验证码后点击下一步触发事件
$("#next").click(function () {
    var randomPhoneCode = $(".phone_code").val()
    $.ajax({
        url:url +"/userInfo/validationPhoneCode",
        dataType:"json",
        type:"post",
        data:"randomPhoneCode=" + randomPhoneCode,
        success:function (data) {
            console.log(data)
              if(1 == data.code){
                    $("#modal_set_phone").hide();
                    $("#modal_set_phone2").show();
              }else if(2 == data.code){
                   layer.msg("验证码错误！")
                  return false;
              }
        }
    })
})

//新手机验证码输入后点击确认
$("#confirm").click(function (){
    var phone =$("#phone2").val()
    var randomPhoneCode = $("#code2").val()
      $.ajax({
          url:url+"/userInfo/changePhone",
          data:"randomPhoneCode="+randomPhoneCode + "&phone="+phone,
          dataType:"json",
          type:"post",
          success:function (data) {
             console.log(data)
              if(1 == data.code){
                  layer.msg("电话修改成功！")
                  $("#modal_set_phone2").hide()
                  $.ajax({
                      url:url +"/userInfo/phone",
                      type:"post",
                      dataType: "json",
                      success:function (data) {
                          $("#cur-phone").text(data.data)
                          $("#cur_phone").text(data.data)
                      }
                  })
              }else if(3 == data.code) {
                  layer.msg("电话已被注册！")
              }else if(4 == data.code){
                  layer.msg("短信验证码错误！")
              }
          }
      })
})

$.ajax({
    url:url +"/userInfo/phone",
    type:"post",
    dataType: "json",
    success:function (data) {
        $("#cur-phone").text(data.data)
        $("#cur_phone").text(data.data)

    }
})



    $("#close-btn2").click(function (){
        $("#modal_set_phone").modal('hide')
        $("#modal_set_phone2").modal('hide').css("display","none")


    })
